package com.taptech.doufu.ui.activity.me

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.taptech.doufu.R
import com.taptech.doufu.constant.AREA_CODE_LIST
import com.taptech.doufu.constant.AreaCode
import com.taptech.doufu.constant.IntentKey
import com.taptech.doufu.ui.activity.base.DiaobaoBaseActivity
import com.taptech.doufu.ui.adapter.AreaCodeAdapter
import com.taptech.doufu.ui.adapter.BaseRecyclerViewAdapter
import kotlinx.android.synthetic.main.activity_area_code.*

class AreaCodeActivity : DiaobaoBaseActivity(){

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_area_code)
        tvTitle.text = getString(R.string.choice_area_code)
        val adapter = AreaCodeAdapter(this)
        adapter.dataList = AREA_CODE_LIST
        adapter.setOnItemClickListener(object : BaseRecyclerViewAdapter.OnItemClickListener<AreaCode>{
            override fun onItemClick(item: AreaCode, position: Int) {
                val intent = Intent()
                intent.putExtra(IntentKey.DATA,item.num)
                setResult(Activity.RESULT_OK,intent)
                finish()
            }
        })
        mRecyclerView.layoutManager = LinearLayoutManager(this)
        mRecyclerView.adapter = adapter


    }

    companion object{
        fun startActivity(context: Context) {
            val intent = Intent()
            intent.setClass(context, AreaCodeActivity::class.java)
            context.startActivity(intent)
        }

        fun startActivityForResult(activity: Activity) {
            val intent = Intent()
            intent.setClass(activity, AreaCodeActivity::class.java)
            activity.startActivityForResult(intent,0)
        }
    }
}